package com.agriculture.competition.controller;

import com.agriculture.common.core.utils.poi.ExcelUtil;
import com.agriculture.common.core.web.controller.BaseController;
import com.agriculture.common.core.web.domain.AjaxResult;
import com.agriculture.common.core.web.page.TableDataInfo;
import com.agriculture.common.log.annotation.Log;
import com.agriculture.common.log.enums.BusinessType;
import com.agriculture.common.security.annotation.RequiresPermissions;
import com.agriculture.competition.domain.JaCompetitionSolution;
import com.agriculture.competition.domain.JaModelManage;
import com.agriculture.competition.domain.vo.JaModelManageVo;
import com.agriculture.competition.service.IJaModelManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 模型管理Controller
 *
 * @author agriculture
 * @date 2024-11-13
 */
@RestController
@RequestMapping("/model")
public class JaModelManageController extends BaseController {
    @Autowired
    private IJaModelManageService jaModelManageService;

    /**
     * 查询模型管理列表
     */
    @RequiresPermissions("competition:model:list")
    @GetMapping("/list")
    public TableDataInfo list(JaModelManageVo jaModelManage) {
        startPage();
        List<JaModelManage> list = jaModelManageService.selectJaModelManageList(jaModelManage);
        return getDataTable(list);
    }

    /**
     * 导出模型管理列表
     */
    @RequiresPermissions("competition:model:export")
    @Log(title = "模型管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JaModelManageVo jaModelManage) {
        List<JaModelManage> list = jaModelManageService.selectJaModelManageList(jaModelManage);
        ExcelUtil<JaModelManage> util = new ExcelUtil<JaModelManage>(JaModelManage.class);
        util.exportExcel(response, list, "模型管理数据");
    }

    /**
     * 获取模型管理详细信息
     */
    //@RequiresPermissions("competition:model:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(jaModelManageService.selectJaModelManageById(id));
    }

    /**
     * 新增模型管理
     */
   // @RequiresPermissions("competition:model:add")
    @Log(title = "模型管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JaModelManage jaModelManage) {
        return toAjax(jaModelManageService.insertJaModelManage(jaModelManage));
    }

    /**
     * 修改模型管理
     */
    //@RequiresPermissions("competition:model:edit")
    @Log(title = "模型管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JaModelManage jaModelManage) {
        return toAjax(jaModelManageService.updateJaModelManage(jaModelManage));
    }

    /**
     * 删除模型管理
     */
   // @RequiresPermissions("competition:model:remove")
    @Log(title = "模型管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(jaModelManageService.deleteJaModelManageByIds(ids));
    }


    /**
     * 获取登陆人的模型====w我的模型
     *
     * @return
     */
    //@RequiresPermissions("competition:model:queryModelList")
    @GetMapping("/queryModelList")
    public TableDataInfo queryList(JaModelManageVo jaModelManageVo) {
        startPage();
        return getDataTable(jaModelManageService.queryList(jaModelManageVo));
    }

   // @RequiresPermissions("competition:model:querySelectModelList")
    @GetMapping("/querySelectModelList")
    public AjaxResult querySelectModelList(JaModelManageVo jaModelManageVo) {
        return success(jaModelManageService.queryList(jaModelManageVo));
    }

    /**
     * 根据类型id查对应的模型list=====首页
     *
     * @return
     */
   // @RequiresPermissions("competition:model:queryModelList")
    @GetMapping("/queryModelByClassfiyId")
    public TableDataInfo queryModelByClassfiyId(@RequestParam("classifyId") long classifyId) {
        startPage();
        List<JaModelManage> list = jaModelManageService.queryModelByClassfiyId(classifyId);
        return getDataTable(list);
    }


    /**
     * 根据比赛id和组id查模型
     *
     * @param jaCompetitionSolution
     * @return
     */
   // @RequiresPermissions("competition:model:queryModelByCompetitionUser")
    @PostMapping("/queryModelByCompetitionUser")
    public AjaxResult queryModelByCompetitionUser(@RequestBody JaCompetitionSolution jaCompetitionSolution) {
        return success(jaModelManageService.queryModelByCompetitionUser(jaCompetitionSolution));
    }
}
